home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Pascal / Source□ / Talk Source / Talk ƒ / Main.p < prev    next >
Encoding:
Text File  |  1992-04-20  |  3.8 KB  |  171 lines  |  [TEXT/PJMM]

  1. program Main;
  2.  
  3. { This program was written by Peter N Lewis, Mar 1992 in THINK Pascal 4.0.1 }
  4. { To compile it you will need the System 7 versions of the Interface files }
  5. { You may use this source in your own free/shareware projects as long as you acknowledge me }
  6. { in your About box and documentation files.  You may include it in commercial products }
  7. { only if I explicitly allow it. }
  8.  
  9.     uses
  10.         OOMainLoop, OOMenus, MyFMenus, OOStatus, MyAppleEvents, MySystem7, PrefsGlobals, Preferences, MyNotifier, {}
  11.         TCPConnections, UDPStuff, Talks, TalkUtils, TalkInput, MyInternetMenu, MyHandleQuitBoth,{}
  12.         MyUtils, BaseGlobals, MyFileSystem, MyUtilities, AppGlobals, TalkTos;
  13.  
  14.     var
  15.         launched_with_option: boolean;
  16.  
  17.     function DoOApp: OSErr;
  18.     begin
  19.         DoOApp := noErr;
  20.     end;
  21.  
  22.     function DoODoc (fs: FSSpec): OSErr;
  23.         var
  24.             pb: CInfoPBRec;
  25.             oe: OSErr;
  26.     begin
  27.         GetPreferences(fs.vRefNum, fs.parID, fs.name);
  28.         DoODoc := noErr;
  29.     end;
  30.  
  31.     function DoQuit: OSErr;
  32.     begin
  33.         DoCommand(0, 0, Cquit);
  34.         DoQuit := noErr;
  35.     end;
  36.  
  37.     procedure UnloadAll;
  38.     begin
  39.         UnloadSeg(@SegmentInit);
  40.         UnloadSeg(@SegmentUtil);
  41.         UnloadSeg(@SegmentUtil2);
  42.         UnloadSeg(@SegmentSystem7);
  43.         UnloadSeg(@SegmentTerm);
  44.         UnloadSeg(@SegmentMFS);
  45.         UnloadSeg(@SegmentMFSByte);
  46.         UnloadSeg(@SegmentPrefs);
  47.     end;
  48.  
  49.     var
  50.         fingerd_cp: connectionIndex;
  51.  
  52.     procedure SetTalkMenu (themenu, theitem: integer);
  53.         var
  54.             t, c: longInt;
  55.     begin
  56.         PurgeSpace(t, c);
  57.         SetIDItemEnable(themenu, theitem, (t > 12000) and (c > 6000));
  58.     end;
  59.  
  60.     function HandleMainEvents (var er: eventRecord): boolean;
  61.         var
  62.             b: boolean;
  63.             fo: WObject;
  64.     begin
  65.         if SetOOMenuBar then
  66.             DrawMenuBar;
  67.         NotifyIdle(in_foreground);
  68.         fo := FrontObject;
  69.         b := fo.WaitForEvent(er, 10);
  70.         b := fo.HandleEvents(er);
  71.         HandleMainEvents := b;
  72.     end;
  73.  
  74.     procedure MyDoFMenu (themenu, theitem: integer);
  75.         var
  76.             s: str255;
  77.     begin
  78.         case themenu of
  79.             M_InternetTo:  begin
  80.                 TalkTo(GetInternetCommand(themenu, theitem));
  81.                 HiliteMenu(0);
  82.             end;
  83.             M_RemoveTo:  begin
  84.                 RemoveInternetCommand(themenu, theitem);
  85.                 HiliteMenu(0);
  86.             end;
  87.             otherwise
  88.                 DoFMenu(themenu, theitem);
  89.         end;
  90.     end;
  91.  
  92.     var
  93.         er: eventRecord;
  94.         s, s1, s2: str255;
  95.         sh: stringHandle;
  96.         paramCount, paramMessage, i: integer;
  97.         af: appFile;
  98.         doparams: boolean;
  99.         oe: OSErr;
  100.         dummyb: boolean;
  101.         cer: connectionEventRecord;
  102.         rfcn, size: longInt;
  103.         cp: connectionIndex;
  104.         dlg: dialogPtr;
  105.         mainloop_dobj: DObject;
  106. begin
  107.     dummyb := GetOSEvent(0, er);
  108.     launched_with_option := BAND(er.modifiers, optionKey) <> 0;
  109.     InitNotify;
  110.     InitUtilities;
  111.  
  112.     if not has_AppleEvents then begin
  113.         CountAppFiles(paramMessage, paramCount);
  114.         if paramMessage <> appOpen then { Must be Open, not Print! }
  115.             begin
  116.             FailAlert('Sorry, I can''t print ', 0);
  117.             halt;
  118.         end;
  119.         for i := 1 to paramCount do begin
  120.             GetAppFiles(i, af);
  121.             with af do
  122.                 if fType = myAppType then begin
  123.                     GetPreferences(vRefNum, 0, fName);
  124.                     ClrAppFiles(i);
  125.                 end;
  126.         end;
  127.     end
  128.     else
  129.         oe := InitAppleEvents(@DoOApp, @DoODoc, nil, @DoQuit);
  130.     new(mainloop_dobj);
  131.     InitMainLoop(mainloop_dobj, @MyDoFMenu);
  132.     InitOOMenus(nil, GetGlobalString(help_menu_text));
  133.     InitPreferences;
  134.     InitQuitBoth('Tokd');
  135.     SetFBoth(Ctalk, @Talk, @SetTalkMenu);
  136.     InitCursor;
  137.     oe := UDPInit;
  138.     oe := InitConnections('');
  139.     if oe = noErr then
  140.         oe := TCPGetMyIPAddr(my_machine_addr);
  141.     if oe <> noErr then begin
  142.         FailAlert('TCP Initialize failed with ', oe);
  143.         halt;
  144.     end;
  145.     InitOOStatus(@HandleStatusCommand);
  146.     InitTalks;
  147.     InitTalkInput;
  148.     InitInternetMenu;
  149.  
  150.     if prefs.auto_talk then
  151.         Talk;
  152.  
  153.     while not quitNow do begin
  154.         UnloadAll;
  155.         dummyb := HandleMainEvents(er);
  156.         HandleEvents;
  157.         if quitNow then
  158.             quitNow := not FinishPreferences;
  159.     end;
  160.  
  161.     FinishInternetMenu;
  162.     FinishTalkInput;
  163.     FinishTalks;
  164.     FinishOOStatus;
  165.     FinishQuitBoth;
  166.     FinishEverything;
  167.     UDPFinish;
  168.     FinishOOmenus;
  169.     FinishMainLoop;
  170.     FinishNotify;
  171. end.